<style scoped>

.item-container{
  padding-left: 5px;
  padding-right: 5px;
  font-size: 0;  
}

ul li{list-style: none;}
.item {
  float: left;
  width: 50%;
  /*clear: both;*/
}

.item {
  flex-direction: column;
  width: 50%;
  background-color: white;
}
.item-fg {
  flex-direction: column;
  width: 50%;
}

.item-block {
  overflow: hidden;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  margin-bottom: 0.8rem;
  font-size: 12px;
}

.item-block img {
  margin: 0 auto;
  width: 100%;
  display:block;
}

.item-block .first-line {
  margin-top: 0.5rem;
  font-size: 1.2rem;
  height: 40px;
  line-height: 20px;
  overflow: hidden;
}
.second-line{
  position: relative;
  padding: 0.5rem 0;
  font-size: 0.8rem;
  overflow: hidden
}

.item-price{
  width: 100%;
}
.item-price_new{
  color:#f10215;
  font-size: 1.2rem;
  font-weight: bold;
  margin-right: 10px;
}
.item-price_old{
  text-decoration: line-through;
  flex: 1;
  font-size: 0.6rem;
  letter-spacing: -1px;
  color: #555;
}
.item-stock{
  display: block;
  margin-bottom: 5px;
  color: #888888;
  font-size: 0.6rem;
  letter-spacing: -1px
}

.offline-notice {
  margin: 3rem 0.5rem 0 0.5rem;
  padding: 2rem 0 2rem 0;
  border-radius: 0.25rem;
  text-align: center;
  background-color: white;
  font-size: 1.65rem;
}

.icon{
  position: absolute;
  right: 0;
  bottom: 0.5rem;
  padding: 0 3px;  
  background-color: #2dcb70;
  color: #fff;
  text-align: center;
  font-size: 18px;
  line-height: 20px
}


</style>
<template>
  <!--方格-->
  <div class="item-container">
    <div class="item-block" v-for="item in lists" :key="item.id" @click="showDetail(item.id)">
        <img class="head-image" :src="item.cover"></img>
        <div style="padding: 0 14px; text-align: justify">
          <div class="first-line">
            <span class="name ellipsis-2">{{item.name}}</span>
          </div>
          <div class="second-line">
            <div class="item-price">
              <span class="item-stock" v-if="item.sellnum > 0">已售:{{item.sellnum }}</span>
              <span class="item-price_new">￥{{item.true_price}}</span>
              <span class="item-price_old">￥{{item.old_price}}</span>
              <Icon type="ios-cart" class='icon'></Icon>
            </div>
          </div>
        </div>
      </div>
  </div>
</template>
<script>
export default {
  name: 'ProductsGrid',
  props: {
    lists: {
      type: Array,
      default: []
    },
  },
 watch: {
   '$route' (to, from) {
    if(to.name == from.name){
      // this.$router.go(to.fullPath)
      // if(to.query.id == from.query.id)
      this.$emit('refreshProduct', to.query.id)
      // location.href = '#'+to.fullPath
      console.log( to.query.id, '没有更新啊')
      // to.path = to.path + '#'+new Date()
    }
    console.log(this.$route.path, to, from)
     console.log(this.getStatus(this.$route.path))
   }
 },
  methods: {
    showDetail(id) {
      this.$router.push('/shop/detail?id=' + id)
    },
    getStatus (urlStr) {
      var urlStrArr = urlStr.split('/')
      return urlStrArr[urlStrArr.length - 1]
    },
    showGroupBuyDetail(id) {
      this.$router.push('/products/groupbuy?id=' + id)
    },
  }
}

</script>
